package com.xishu.controller;

import com.xishu.annotation.valid.MethodValidator;
import com.xishu.entity.shop.Catalog;
import com.xishu.exception.ResponseStatusException;
import com.xishu.response.ResponseData;
import com.xishu.service.CommonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@Api(description = "场景与品类的映射关系")
@RestController
public class SceneCatalogMappingController {

    @ApiOperation(value = "创建关系")
    @PostMapping(value = ("/user/scene/catalog/mapping"), produces = ("application/json;charset=UTF-8"))
    @MethodValidator(checkShop = true, checkShopId = true)
    public ResponseData create(@RequestBody Catalog catalog) throws Exception {
        return CommonService.getInstance().createObject(catalog);
    }

    @ApiOperation(value = "修改关系")
    @PutMapping(value = ("/user/scene/catalog/mapping/modify"), produces = ("application/json;charset=UTF-8"))
    @MethodValidator(checkShop = true)
    public ResponseData modify(@RequestBody Catalog catalog) throws Exception {
        return CommonService.getInstance().updateObject(catalog);
    }

    @ApiOperation(value = "查询关系")
    @PutMapping(value = ("/user/scene/catalog/mapping"), produces = ("application/json;charset=UTF-8"))
    @MethodValidator(mustLogin = false)
    public ResponseData search(@RequestBody Catalog catalog) throws Exception {
        return CommonService.getInstance().searchResponse(catalog);
    }

    @ApiOperation(value = "删除关系")
    @DeleteMapping(value = ("/user/scene/catalog/mapping"), produces = ("application/json;charset=UTF-8"))
    @MethodValidator(checkShop = true)
    public ResponseData delete(@RequestBody Catalog catalog) throws Exception {
        return CommonService.getInstance().delete(catalog);
    }
}
